package util;
import static skeleton.Board.*;

public class Situation {
	public int rows, cols, top=0, left=0;
	public int[][] data;
	public int nextRow, nextCol;
	public Situation(int row, int col) {
		rows = row; cols = col;
		data = new int[rows][cols];
	}
	public Situation(int[][] board) {
		int top=LEN, bottom=-1, left=LEN, right=-1;
		for (int i=0; i<LEN; ++i) {
			for (int j=0; j<LEN; ++j)
				if (board[i][j] != EMPTY) {
					if (i < top) top = i;
					if (i > bottom) bottom = i;
					if (j < left) left = j;
					if (j > right) right = j;
				}
		}
		if (top == LEN) {
			rows = cols = 0;
			return;
		}
		rows = bottom - top + 1;
		cols = right - left + 1;
		data = new int[rows][cols];
		for (int i=top; i<=bottom; ++i)
			for (int j=left; j<=right; ++j)
				data[i-top][j-left] = board[i][j];
		this.top = top;
		this.left = left;
	}
	public void show() {
		System.out.println("rows = " + rows + "   " + "cols = " + cols);
		for (int i=0; i<rows; ++i) {
			for (int j=0; j<cols; ++j)
				if (data[i][j] == EMPTY) System.out.print('*');
				else System.out.print(data[i][j]);
			System.out.println();
		}
	}
}
